import Vue from 'vue'
import entryFactory from 'bpmn-js-properties-panel/lib/factory/EntryFactory'
const cmdHelper = require('bpmn-js-properties-panel/lib/helper/CmdHelper')
const getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject

const prase = function (data) {
  if (data) {
    return `${data.value}-${data.name}`
  } else {
    return ''
  }
}
export default function (group, element, translate) {
  for (let i = 0; i < group.entries.length; i++) {
    switch (group.entries[i].id) {
      case 'candidateStarterGroups':
        group.entries[i] = entryFactory.textField({
          id: 'candidateStarterGroups',
          label: translate('Candidate Starter Groups'),
          modelProperty: 'candidateStarterGroups',
          description: translate('Specify more than one group as a comma separated list.'),
          get: function (element, node) {
            var bo = getBusinessObject(element)
            var candidateStarterGroups = bo.get('camunda:candidateStarterGroups')

            return {
              candidateStarterGroups: candidateStarterGroups || prase(Vue.ls.get(`candidateStarterGroups:${document.querySelector('#camunda-id').value}`)) || ''
            }
          },

          set: function (element, values) {
            var bo = getBusinessObject(element)
            return cmdHelper.updateBusinessObject(element, bo, {
              'camunda:candidateStarterGroups': values.candidateStarterGroups || prase(Vue.ls.get(`candidateStarterGroups:${document.querySelector('#camunda-id').value}`)) || undefined
            })
          }
        })
        break
      case 'candidateStarterUsers':
        group.entries[i] = entryFactory.textField({
          id: 'candidateStarterUsers',
          label: translate('Candidate Starter Users'),
          modelProperty: 'candidateStarterUsers',
          description: translate('Specify more than one user as a comma separated list.'),
          get: function (element, node) {
            var bo = getBusinessObject(element)
            var candidateStarterUsers = bo.get('camunda:candidateStarterUsers')

            return {
              candidateStarterUsers: candidateStarterUsers || prase(Vue.ls.get(`candidateStarterUsers:${document.querySelector('#camunda-id').value}`)) || ''
            }
          },

          set: function (element, values) {
            var bo = getBusinessObject(element)
            return cmdHelper.updateBusinessObject(element, bo, {
              'camunda:candidateStarterUsers': values.candidateStarterUsers || prase(Vue.ls.get(`candidateStarterUsers:${document.querySelector('#camunda-id').value}`)) || undefined
            })
          }
        })
        break
    }
  }
}
